﻿Imports AUtility

Partial Public Class KalendarPrikaz
    Inherits System.Web.UI.Page

    Private Sub DeleteDogadaj()
        Dim deleteStr As String = String.Format("DELETE Dogadaj WHERE DogadajId = {0}", Request.QueryString("DeleteDogadajId"))
        DataAccess.ExecuteSql(GlobalTenisLiga.ConnectionString, deleteStr)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try
            If (Request.QueryString("DeleteDogadajId") IsNot Nothing) Then
                DeleteDogadaj()
            End If
       
            Dim selectStr As String = "SELECT * FROM Dogadaj WHERE Datum between GetDate()-1 AND GetDate() ORDER BY Datum ASC"

            Dim totalMatchesCount As Integer = 0
            Dim dt As DataTable = New DataTable
            AUtility.DataAccess.FillTable(GlobalTenisLiga.ConnectionString, selectStr, dt)
            totalMatchesCount = totalMatchesCount + dt.Rows.Count
            If dt.Rows.Count > 0 Then
                Response.Write("<b>Prošlo:</b><br>")
            End If

            For Each row As DataRow In dt.Rows

                row("DogadajOpis") = row("DogadajOpis").ToString().Replace("00:00", "00")
                row("DogadajOpis") = row("DogadajOpis").ToString().Replace("30:00", "00")

                Response.Write("<hr>")
                Response.Write(row("DogadajOpis"))
            Next
            Response.Write("<hr>")

            selectStr = "SELECT * FROM Dogadaj WHERE Datum > GetDate() ORDER BY Datum ASC"
            dt = New DataTable()
            AUtility.DataAccess.FillTable(GlobalTenisLiga.ConnectionString, selectStr, dt)
            totalMatchesCount = totalMatchesCount + dt.Rows.Count
            If dt.Rows.Count > 0 Then
                Response.Write("<b>Dolazi:</b><br>")
            End If
            For Each row As DataRow In dt.Rows

                row("DogadajOpis") = row("DogadajOpis").ToString().Replace("00:00", "00")
                row("DogadajOpis") = row("DogadajOpis").ToString().Replace("30:00", "30")

                Response.Write("<hr>")
                Response.Write(row("DogadajOpis"))
                If Not row.IsNull("Cookie") Then
                    If Request.Cookies("CurrentUser") IsNot Nothing Then
                        If row("Cookie").ToString() = Request.Cookies("CurrentUser").Value Then
                            Dim deleteStr As String = String.Format("<br><div class=example2><a href=KalendarPrikaz.aspx?DeleteDogadajId={0} class=delete>Obriši</a></div>", row("DogadajId"))
                            Response.Write(deleteStr)
                        End If
                    End If
                End If
                If (Not row.IsNull("Igrac1") AndAlso row("Igrac1").ToString() <> String.Empty) Then
                    Dim newWidow As String = String.Format("http://tenisligaplayers.tk-osmica.hr/Pages/Blog/HeadToHead.aspx?I1={0}&I2={1}", row("Igrac1"), row("Igrac2"))
                    Response.Write(String.Format("  <a href='#' onClick=""window.open('{0}')"">Najava</a>", newWidow))
                End If

            Next
            Response.Write("<hr>")

            If (totalMatchesCount = 0) Then
                Response.Write("Što bi?<br> Nitko ne igra !?!?")
                Response.Write("<hr>")
            End If

            selectStr = "SELECT TOP 1 * FROM Sezona ORDER BY DatumOd DESC"
            Dim srow As DataRow = DataAccess.GetDataRow(GlobalTenisLiga.ConnectionString, selectStr)

            Response.Write(String.Format("{0}<br><b>Kraj sezone {1}</b><br>", Convert.ToDateTime(srow("DatumDo")).ToString("dd.MM.yyyy"), srow("SezonaNaziv")))
            Response.Write("<hr>")
            'Response.Write("1.11.2009<br><b>Početak sezone 2009/11-12</b><br>")

        Catch ex As Exception
            Response.Write("Error:<br>" + ex.Message)
        End Try

    End Sub

End Class